package cn.wolfcode.luowowo.comment.service.impl;

import cn.wolfcode.luowowo.comment.domain.HotelComment;
import cn.wolfcode.luowowo.comment.repository.HotelCommentRepository;
import cn.wolfcode.luowowo.comment.service.IHotelCommentService;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

/**
 * 酒店评论
 *
 * @author win
 */
@Service
public class HotelCommentServiceImpl implements IHotelCommentService {

    @Autowired
    private HotelCommentRepository hotelCommentRepository;

    @Autowired
    private MongoTemplate template;

    @Override
    public HotelComment saveOrUpdate(HotelComment hotelComment) {
        return hotelCommentRepository.save(hotelComment);
    }

    @Override
    public List<HotelComment> queryByHotelId(Long hotelId) {
        return hotelCommentRepository.findByHotelId(hotelId);
    }

    @Override
    public List<HotelComment> queryByUserId(Long uid) {
        return hotelCommentRepository.findByUserId(uid);
    }

    @Override
    public Long queryCountByHotelId(Long hotelId) {
        Query query = new Query();
        query.addCriteria(Criteria.where("hotelId").is(hotelId));
        return template.count(query, HotelComment.class);
    }
}
